package com.vicene.gmail.search.controller;

import com.vicene.gmail.search.service.MailSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import com.vicene.gmail.search.vo.SearchParam;
import com.vicene.gmail.search.vo.SearchResult;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {

    @Autowired
    MailSearchService mailSearchService;

    @GetMapping("list.html")
    public String listPage(SearchParam searchParam , Model model , HttpServletRequest request){
        String queryString = request.getQueryString();
        searchParam.set_queryString(queryString);
        SearchResult result =  mailSearchService.search(searchParam);
        model.addAttribute("result" , result);
        return "list";
    }
}
